using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_GB1109
    {
        public DataRow Convert2ICC_GB1109(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_GB1109(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ABAID"] = " ".PadRight(20 ); 
         dwReturn["TERMNO"] = " ".PadRight(8 ); 
         dwReturn["PROCESSED"] = " ".PadRight(1 ); 
         dwReturn["NEWDATE"] = " ".PadRight(8 ); 
         dwReturn["NEWTIME"] = " ".PadRight(0 ); 
         dwReturn["NEWUSER"] = " ".PadRight(8 ); 
         dwReturn["CHGDATE"] = " ".PadRight(8 ); 
         dwReturn["CHGTIME"] = " ".PadRight(0 ); 
         dwReturn["CHGUSER"] = " ".PadRight(8 ); 
         dwReturn["GLMANDANT"] = " ".PadRight(2 ); 
         dwReturn["GPSPPART"] = " ".PadRight(10 ); 
         dwReturn["GPFBPART"] = " ".PadRight(10 ); 
         dwReturn["GPZWPART"] = " ".PadRight(10 ); 
         dwReturn["GLPARTIE"] = " ".PadRight(7 ); 
         dwReturn["GLPARTIEKZ"] = " ".PadRight(1 ); 
         dwReturn["GPGART"] = " ".PadRight(20 ); 
         dwReturn["GPGVAR"] = " ".PadRight(3 ); 
         dwReturn["GPGFARBE"] = " ".PadRight(10 ); 
         dwReturn["GLLBEH"] = " ".PadRight(10 ); 
         dwReturn["GLLBEHI"] = " ".PadRight(10 ); 
         dwReturn["GLBSTNET"] = " ".PadRight(0 ); 
         dwReturn["GLBSTKG"] = " ".PadRight(0 ); 
         dwReturn["GLKOND"] = " ".PadRight(0 ); 
         dwReturn["GLBSTKA"] = " ".PadRight(0 ); 
         dwReturn["GLBSTSP"] = " ".PadRight(0 ); 
         dwReturn["TARGETQTY"] = " ".PadRight(0 ); 
         dwReturn["GLLO"] = " ".PadRight(2 ); 
         dwReturn["GLLB"] = " ".PadRight(2 ); 
         dwReturn["GLLP"] = " ".PadRight(8 ); 
         dwReturn["CPLO"] = " ".PadRight(2 ); 
         dwReturn["CPLB"] = " ".PadRight(2 ); 
         dwReturn["CPLP"] = " ".PadRight(8 ); 
         dwReturn["JP01"] = " ".PadRight(10 ); 
         dwReturn["JP02"] = " ".PadRight(10 ); 
         dwReturn["JP03"] = " ".PadRight(10 ); 
         dwReturn["JP04"] = " ".PadRight(20 ); 
         dwReturn["JP05"] = " ".PadRight(20 ); 
         dwReturn["JP06"] = " ".PadRight(20 ); 
         dwReturn["JP07"] = " ".PadRight(30 ); 
         dwReturn["JP08"] = " ".PadRight(30 ); 
         dwReturn["JP09"] = " ".PadRight(30 ); 
         dwReturn["JP10"] = " ".PadRight(300 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_GB1109(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_GB1109(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_GB1109(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_GB1109(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_GB1109(dwLocal, ITXDBVERSION);
            }
            UpdateICC_GB1109(dwLocal);
        }
        public void InsertICC_GB1109(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_GB1109(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_GB1109(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_GB1109 WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_GB1109  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_GB1109";
            Return = Result;
            return Return;
        }
        public void DeleteICC_GB1109(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_GB1109   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_GB1109(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_GB1109 SET "
                    +"ABAID= :ABAID,"
                    +"TERMNO= :TERMNO,"
                    +"PROCESSED= :PROCESSED,"
                    +"NEWDATE= :NEWDATE,"
                    +"NEWTIME= :NEWTIME,"
                    +"NEWUSER= :NEWUSER,"
                    +"CHGDATE= :CHGDATE,"
                    +"CHGTIME= :CHGTIME,"
                    +"CHGUSER= :CHGUSER,"
                    +"GLMANDANT= :GLMANDANT,"
                    +"GPSPPART= :GPSPPART,"
                    +"GPFBPART= :GPFBPART,"
                    +"GPZWPART= :GPZWPART,"
                    +"GLPARTIE= :GLPARTIE,"
                    +"GLPARTIEKZ= :GLPARTIEKZ,"
                    +"GPGART= :GPGART,"
                    +"GPGVAR= :GPGVAR,"
                    +"GPGFARBE= :GPGFARBE,"
                    +"GLLBEH= :GLLBEH,"
                    +"GLLBEHI= :GLLBEHI,"
                    +"GLBSTNET= :GLBSTNET,"
                    +"GLBSTKG= :GLBSTKG,"
                    +"GLKOND= :GLKOND,"
                    +"GLBSTKA= :GLBSTKA,"
                    +"GLBSTSP= :GLBSTSP,"
                    +"TARGETQTY= :TARGETQTY,"
                    +"GLLO= :GLLO,"
                    +"GLLB= :GLLB,"
                    +"GLLP= :GLLP,"
                    +"CPLO= :CPLO,"
                    +"CPLB= :CPLB,"
                    +"CPLP= :CPLP,"
                    +"JP01= :JP01,"
                    +"JP02= :JP02,"
                    +"JP03= :JP03,"
                    +"JP04= :JP04,"
                    +"JP05= :JP05,"
                    +"JP06= :JP06,"
                    +"JP07= :JP07,"
                    +"JP08= :JP08,"
                    +"JP09= :JP09,"
                    +"JP10= :JP10,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString(); 
          or1.Parameters.Add("TERMNO", OracleType.NVarChar).Value = dwData["TERMNO"].ToString(); 
          or1.Parameters.Add("PROCESSED", OracleType.NVarChar).Value = dwData["PROCESSED"].ToString(); 
          or1.Parameters.Add("NEWDATE", OracleType.NVarChar).Value = dwData["NEWDATE"].ToString(); 
          or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString(); 
          or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString(); 
          or1.Parameters.Add("CHGDATE", OracleType.NVarChar).Value = dwData["CHGDATE"].ToString(); 
          or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString(); 
          or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString(); 
          or1.Parameters.Add("GLMANDANT", OracleType.NVarChar).Value = dwData["GLMANDANT"].ToString(); 
          or1.Parameters.Add("GPSPPART", OracleType.NVarChar).Value = dwData["GPSPPART"].ToString(); 
          or1.Parameters.Add("GPFBPART", OracleType.NVarChar).Value = dwData["GPFBPART"].ToString(); 
          or1.Parameters.Add("GPZWPART", OracleType.NVarChar).Value = dwData["GPZWPART"].ToString(); 
          or1.Parameters.Add("GLPARTIE", OracleType.NVarChar).Value = dwData["GLPARTIE"].ToString(); 
          or1.Parameters.Add("GLPARTIEKZ", OracleType.NVarChar).Value = dwData["GLPARTIEKZ"].ToString(); 
          or1.Parameters.Add("GPGART", OracleType.NVarChar).Value = dwData["GPGART"].ToString(); 
          or1.Parameters.Add("GPGVAR", OracleType.NVarChar).Value = dwData["GPGVAR"].ToString(); 
          or1.Parameters.Add("GPGFARBE", OracleType.NVarChar).Value = dwData["GPGFARBE"].ToString(); 
          or1.Parameters.Add("GLLBEH", OracleType.NVarChar).Value = dwData["GLLBEH"].ToString(); 
          or1.Parameters.Add("GLLBEHI", OracleType.NVarChar).Value = dwData["GLLBEHI"].ToString(); 
          or1.Parameters.Add("GLBSTNET", OracleType.NVarChar).Value = dwData["GLBSTNET"].ToString(); 
          or1.Parameters.Add("GLBSTKG", OracleType.NVarChar).Value = dwData["GLBSTKG"].ToString(); 
          or1.Parameters.Add("GLKOND", OracleType.NVarChar).Value = dwData["GLKOND"].ToString(); 
          or1.Parameters.Add("GLBSTKA", OracleType.NVarChar).Value = dwData["GLBSTKA"].ToString(); 
          or1.Parameters.Add("GLBSTSP", OracleType.NVarChar).Value = dwData["GLBSTSP"].ToString(); 
          or1.Parameters.Add("TARGETQTY", OracleType.NVarChar).Value = dwData["TARGETQTY"].ToString(); 
          or1.Parameters.Add("GLLO", OracleType.NVarChar).Value = dwData["GLLO"].ToString(); 
          or1.Parameters.Add("GLLB", OracleType.NVarChar).Value = dwData["GLLB"].ToString(); 
          or1.Parameters.Add("GLLP", OracleType.NVarChar).Value = dwData["GLLP"].ToString(); 
          or1.Parameters.Add("CPLO", OracleType.NVarChar).Value = dwData["CPLO"].ToString(); 
          or1.Parameters.Add("CPLB", OracleType.NVarChar).Value = dwData["CPLB"].ToString(); 
          or1.Parameters.Add("CPLP", OracleType.NVarChar).Value = dwData["CPLP"].ToString(); 
          or1.Parameters.Add("JP01", OracleType.NVarChar).Value = dwData["JP01"].ToString(); 
          or1.Parameters.Add("JP02", OracleType.NVarChar).Value = dwData["JP02"].ToString(); 
          or1.Parameters.Add("JP03", OracleType.NVarChar).Value = dwData["JP03"].ToString(); 
          or1.Parameters.Add("JP04", OracleType.NVarChar).Value = dwData["JP04"].ToString(); 
          or1.Parameters.Add("JP05", OracleType.NVarChar).Value = dwData["JP05"].ToString(); 
          or1.Parameters.Add("JP06", OracleType.NVarChar).Value = dwData["JP06"].ToString(); 
          or1.Parameters.Add("JP07", OracleType.NVarChar).Value = dwData["JP07"].ToString(); 
          or1.Parameters.Add("JP08", OracleType.NVarChar).Value = dwData["JP08"].ToString(); 
          or1.Parameters.Add("JP09", OracleType.NVarChar).Value = dwData["JP09"].ToString(); 
          or1.Parameters.Add("JP10", OracleType.NVarChar).Value = dwData["JP10"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
